import React, { useEffect, useState } from "react";
import XTable from "../XTable";
import './page.css'
import { Button, Form, Input, Radio, DatePicker, Space, Select } from 'antd';
import { getOrders, getCurrencies, getCustomers, getPayterms } from "@/database";
import XSelect from "@/demos/XSelect";
import { customerSelectColumns, orderTableColumns, paytermSelectColumns } from "@/constants";

let isLoaded = false
import dayjs from 'dayjs';

const Orders = ({onDbClickRow}) => {
    const [orders, setOrders] = useState([]);
   
    useEffect(() => {
        console.log('render page...', isLoaded)
        if (!isLoaded) {
            getOrders().then((data) => {
                setOrders(data)
            })
            isLoaded = true;
        }
    }, []);
    const onSelectChange = (row, colIdx) => {
        onDbClickRow(row)
    }
    return (
        <div>
            <XTable columns={orderTableColumns} data={orders} selectMode="row" selectable={true}
                onSelectChange={onSelectChange} />
        </div>
    )
}

export default Orders